ARG PHP_VERSION=8.3
# 镜像 具体版本
FROM php:${PHP_VERSION}-fpm-alpine

WORKDIR  /opt/www

# 安装 Composer
ENV COMPOSER_HOME /root/composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
ENV PATH $COMPOSER_HOME/vendor/bin:$PATH
RUN composer conf -g repo.packagist composer https://mirrors.aliyun.com/composer/

#使用sed工具将字符串dl-cdn.alpinelinux.org替换为mirrors.aliyun.com
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
#包更新
RUN apk update

#创建下载软件存放目录
RUN mkdir /home/download

# 设置时区
RUN apk add tzdata \
    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone

#安装 autoconf（无configure脚本时）,针对phpize
RUN apk add autoconf

#安装 C 编译器
RUN apk add gcc \
        g++ \
        zlib-dev \
        libc-dev \
        openssl-dev \
        curl-dev  \
        libcurl   \
        linux-headers

#安装openssl
RUN apk add openssl


#gcc,针对./configure
# RUN apk add --update --no-cache \
#         g++ \
#         gcc \
#         libxslt-dev \
#         re2c \
#         openssl-dev

#安装make
RUN apk add make

# 安装git
RUN apk add git

#gd库
RUN apk add \
        freetype-dev \
        libpng-dev \
        libjpeg-turbo-dev

# 安装sockets扩展
RUN docker-php-ext-install sockets
#
#RUN docker-php-ext-install openssl

RUN docker-php-ext-install gd
#安装数据库扩展
RUN docker-php-ext-install pdo pdo_mysql

#zip库
RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-install zip
#bcmath
RUN docker-php-ext-install bcmath


#安装FFmpeg
#RUN apk add  \
#        yasm \
#        ffmpeg


#安装librabbitmq-c和librabbitmq-c-dev,安装amqb
RUN apk add --no-cache -U rabbitmq-c \
        rabbitmq-c-dev
#安装Redis，mongodb，amqp,swoole
# RUN pecl install redis \home/
#     && docker-php-ext-enable redis
# RUN pecl install mongodb \
#    && docker-php-ext-enable mongodb
# RUN pecl install amqp \
#     && docker-php-ext-enable amqp
#pecl访问超时使用
RUN cd /home/download
COPY ext/redis-5.3.7.tgz /home/download/redis-5.3.7.tgz
RUN pecl install /home/download/redis-5.3.7.tgz \
    && docker-php-ext-enable redis
#COPY ext/mongodb-1.10.0.tgz /home/download/mongodb-1.10.0.tgz
#RUN pecl install /home/download/mongodb-1.10.0.tgz \
#    && docker-php-ext-enable mongodb
COPY ext/amqp-1.11.0.tgz /home/download/amqp-1.11.0.tgz
RUN pecl install /home/download/amqp-1.11.0.tgz \
    && docker-php-ext-enable amqp
COPY ext/swoole-5.0.3.tgz /home/download/swoole-5.0.3.tgz
RUN mkdir -p /usr/src/php/ext
RUN tar -zxvf /home/download/swoole-5.0.3.tgz
RUN mv -f swoole-5.0.3 /usr/src/php/ext/swoole
#RUN docker-php-ext-install swoole
#RUN pecl install /home/download/swoole-5.0.3.tgz -D  'enable-sockets="yes" enable-openssl="yes"  \
#    enable-http2="yes" enable-mysqlnd="yes" enable-swoole-curl="yes"' \
#    && docker-php-ext-enable swoole
RUN cd /usr/src/php/ext/swoole && \
    phpize && \
    ./configure --enable-openssl --enable-sockets --enable-mysqlnd --enable-swoole-curl && \
    make && make install && docker-php-ext-enable swoole
RUN docker-php-ext-install pcntl


RUN addgroup -g 1000 -S www && \
    adduser -u 1000 -S www -G www

#USER root

COPY --chown=www:www-data . /var/www

RUN chown -R www:www-data /var/www
RUN chmod -R ug+w /var/www

# RUN cd ~/download

# 生成swoole安装目录
#1. 下载swoole安装包
# RUN mkdir -p /usr/src/php/ext
# RUN wget https://pecl.php.net/get/swoole-4.8.0.tgz
#2. 解压swoole安装包
# RUN tar -zxvf swoole-4.8.0.tgz
#3. 将解压出来的安装包移动到docker-php-ext-install对应的目录
# RUN mv -f swoole-4.8.0 /usr/src/php/ext/swoole
# RUN docker-php-ext-install swoole


#4. 安装swoole

#安装ffmpeg扩展
#RUN git clone https://github.com/tony2001/ffmpeg-php.git




#./configure --with-php-conf=/usr/local/bin/php-conf
#mv ffmpeg_frame.loT ffmpeg_frame.lo
#mv ffmpeg_movie.loT ffmpeg_movie.lo
